package com.wzw.tmaceventbus;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.wzw.tmaceventbus.eventbus.TmacEventBus;
import com.wzw.tmaceventbus.eventbus.TmacSubscribe;
import com.wzw.tmaceventbus.eventbus.TmacSubscribeThreadMode;

public class MainActivity extends AppCompatActivity {
    private TextView textView;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView = findViewById(R.id.tvMsg);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(MainActivity.this, SecondActivity.class));
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        TmacEventBus.getDefault().register(this);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        TmacEventBus.getDefault().unRegister(this);
    }

    @TmacSubscribe(THREAD_MODE = TmacSubscribeThreadMode.MAIN)
    public void receive(CommonEvent event,String a) {
        if (event != null) {
            textView.setText(textView.getText() + event.content);
        }
    }

    @TmacSubscribe(THREAD_MODE = TmacSubscribeThreadMode.MAIN)
    public void receive2(CommonEvent2 event) {
        if (event != null) {
            textView.setText(textView.getText() + event.content);
        }
    }
}